package com.base.common

import android.text.TextUtils
import android.util.Log
import android.view.View
import androidx.multidex.MultiDexApplication
import com.alibaba.android.arouter.launcher.ARouter
import com.drake.net.NetConfig
import com.drake.net.interceptor.LogRecordInterceptor
import com.drake.net.interfaces.NetErrorHandler
import com.drake.net.okhttp.setConverter
import com.drake.net.okhttp.setErrorHandler
import com.kotlin.base.converter.SerializationConverter
import com.kotlin.base.utils.PropertiesUtil
import dagger.hilt.android.HiltAndroidApp


open class BaseApplication : MultiDexApplication() {

    override fun onCreate() {
        super.onCreate()
        val isRelease: String = PropertiesUtil.getProperty("isRelease")
        if (!TextUtils.equals(isRelease, "true")) {
            ARouter.openLog()
            ARouter.openDebug()
        }
        ARouter.init(this)
        NetConfig.init("http://localhost:80/") {


            setConverter(converter =SerializationConverter() )
            addInterceptor(LogRecordInterceptor(BuildConfig.DEBUG))
            setErrorHandler(object : NetErrorHandler {
                override fun onError(e: Throwable) {
                    super.onError(e)
                    Log.e("err",e.toString())
                }

                override fun onStateError(e: Throwable, view: View) {
                    super.onStateError(e, view)
                }
            })
        }
    }

}